package com.kcsoft.controller;

import com.kcsoft.pojo.Command;
import com.kcsoft.pojo.PageBean;
import com.kcsoft.pojo.Result;
import com.kcsoft.service.CommandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/command")
public class CommandController {

    @Autowired
    private CommandService commandService;

    @PostMapping("/add")
    public Result add(String command) {
        Command c = commandService.findByCommand(command);
        if (c != null) {
            return Result.error("命令已存在");
        }
        commandService.add(command);
        return Result.success();
    }

    @PostMapping("/list")
    public Result<PageBean<Command>> list(Integer pageNum, Integer pageSize) {
        PageBean<Command> pb = commandService.list(pageNum, pageSize);
        return Result.success(pb);
    }

    @PostMapping("/delCommand")
    public Result delCommand(Integer id) {
        commandService.delCommand(id);
        return Result.success();
    }

}
